#ifndef EABSTRACTVIEW_H
#define EABSTRACTVIEW_H

#include <QQuickPaintedItem>

#include "EAbstractLayer.h"

/**
 * @brief 视图基类
 * @details
 * 目前使用 QPainter 绘制
 *
 * 如果每个组件单独继承QQuickPaintedItem，交叉的区域不能绘制，统一在view回调
 */
class EAbstractView : public QQuickPaintedItem
{
    Q_OBJECT
    Q_INTERFACES(QQmlParserStatus)
    //已有属性 fillColor 填充颜色
    /// 点击事件开关
    Q_PROPERTY(bool acceptClick READ getAcceptClick WRITE setAcceptClick NOTIFY acceptClickChanged)
    /// 悬停事件开关
    Q_PROPERTY(bool acceptHover READ getAcceptHover WRITE setAcceptHover NOTIFY acceptHoverChanged)
    /// 字体
    Q_PROPERTY(QFont font READ getFont WRITE setFont NOTIFY fontChanged)
public:
    explicit EAbstractView(QQuickItem *parent = nullptr);

    bool getAcceptClick() const;
    void setAcceptClick(bool accept);

    bool getAcceptHover() const;
    void setAcceptHover(bool accept);

    QFont getFont() const;
    void setFont(const QFont &font);

    // 绘制
    void paint(QPainter *painter) override;

protected:
    void classBegin() override;
    void componentComplete() override;
    //void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override;
    //void childEvent(QChildEvent *event) override;
    // 右键点击留给菜单等操作，组件目前只接收左键
    void mousePressEvent(QMouseEvent *event) override;
    void mouseDoubleClickEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    //void hoverEnterEvent(QHoverEvent *event) override;
    void hoverLeaveEvent(QHoverEvent *event) override;
    void hoverMoveEvent(QHoverEvent *event) override;
    void mouseOnMove(const QPoint &pos);
    void wheelEvent(QWheelEvent *event) override;

signals:
    void acceptClickChanged();
    void acceptHoverChanged();
    void fontChanged();
    void rightClick(const QPoint &point);

public slots:
    // 刷新
    void refresh();

protected:
    QList<EAbstractLayer*> layerList;

private:
    // 点击事件 default=true
    bool acceptClick;
    // 悬停事件 default=false
    bool acceptHover;
    // 字体设置
    QFont font;
};

#endif // EABSTRACTVIEW_H
